package com.study.lxy.springmvc.controller;

import com.study.lxy.springmvc.util.UserPrincipleTaker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class HelloController implements EnvironmentAware {
    private Environment environment;
    private Logger logger = LoggerFactory.getLogger(HelloController.class);

    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index(Model model){
        logger.info("======= processed by index ==========");
        logger.info("userPrinciple is {}", UserPrincipleTaker.get());
        model.addAttribute("message","Go Go Go!");
        return "go.jsp";
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }
}
